//
// Created by gyc on 2020/9/22.
//

#include "../../common.h"

class Solution {
public:
    int search(vector<int> &nums, int target) {
        int left = 0, right = nums.size();
        while (left < right) {
            int mid = left + ((right - left) >> 1);
            if (target < nums[mid]) {
                right = mid;
            } else if (target > nums[mid]) {
                left = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
};

int main() {

    // [-1,0,3,5,9,12]
    //2

    vector<int> vec{-1, 0, 3, 5, 9, 12};
    cout << Solution().search(vec, 2) << endl;
}
